package net.zjitc.controller.admin;

import net.zjitc.pojo.Orders;
import net.zjitc.service.OrderService;
import net.zjitc.vo.OrderConditionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author admin
 * @Date 2019/4/11 8:21
 */
@Controller
@RequestMapping("/manage/order")
public class AdminOrderController {
    @Autowired
    OrderService orderService;


    @RequestMapping("/findAllOrders")
    public String findAllOrders(Model model){
        List<Orders> ordersList = orderService.findAll();
        model.addAttribute("olist",ordersList);
        return "/admin/orders/list.jsp";
    }


    @RequestMapping("/findByCondition")
    @ResponseBody
    public List<Orders> findByCondition(OrderConditionVo vo){
        List<Orders> list = orderService.findByCondition(vo);
        return list;
    }


    @RequestMapping("/findOrderDetails")
    public String findOrderDetails(String id,Model model){
        Orders orders = orderService.findOrderDeatils(id);
        model.addAttribute("order",orders);
        return "/admin/orders/view.jsp";

    }
    @RequestMapping("/deleteOrderById")
    public String deleteById(String id){
        orderService.deleteOrderById(id);
        return "redirect:/manage/order/findAllOrders.do";

    }
}
